package com.devenv.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 软件版本实体类
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "software_version")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SoftwareVersion {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "software_id", nullable = false)
    private Long softwareId;

    @Column(name = "version", nullable = false, length = 50)
    private String version;

    @Column(name = "release_date")
    private LocalDate releaseDate;

    @Column(name = "download_path", nullable = false, length = 500)
    private String downloadPath;

    @Column(name = "file_size")
    private Long fileSize = 0L;

    @Column(name = "is_latest")
    private Boolean isLatest = false;

    @Column(name = "changelog", columnDefinition = "TEXT")
    private String changelog;

    @Column(name = "system_requirements", columnDefinition = "TEXT")
    private String systemRequirements;

    @Column(name = "status", length = 20)
    private String status = "ACTIVE";

    @Column(name = "download_count")
    private Long downloadCount = 0L;

    @Column(name = "checksum_md5", length = 32)
    private String checksumMd5;

    @Column(name = "checksum_sha256", length = 64)
    private String checksumSha256;

    @CreationTimestamp
    @Column(name = "created_at")
    private LocalDateTime createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    // 关联关系
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "software_id", insertable = false, updatable = false)
    private Software software;
}
